<template>
	<view>
		<div class="top" v-if="orderInfo">您收到1条订单任务！</div>
		<div class="get">
			<image @click="sureOrder" src="../../static/receving_01.png" mode=""></image>
		</div>
		<div class="text">请在N分钟内接单，超时订单失效！</div>
		<div class="no">
			<image src="../../static/receving_02.png" mode=""></image>
			<div class="input_box">
				<input type="text" v-model="reason" placeholder="请输入拒单原因" />
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderInfo:null,
				searchObj:{},
				reason:"",
				aroundGet:"",
			}
		},
		methods: {
			getOrder(){
				this.aroundGet = setInterval(()=>{
					this.$get('recovery/searchorder', {
					}, (res) => {
						console.log(res)
						if(res){
							this.orderInfo = res.order_info;
							this.searchObj = res;
						}else{
							this.orderInfo = null;
						}
					})
				},1000)
			},
			sureOrder(){
				if(!this.searchObj.id){
					uni.showToast({
						title:"暂无订单",
						icon:"none"
					})
					return
				}
				this.$get('recovery/getorder', {id:this.searchObj.id
				}, (res) => {
					uni.showToast({
						title:"接单成功！",
					})
				})
			},
			refuseOrder(){
				uni.showToast({
					title:"暂无订单",
					icon:"none"
				})
				return
				if(!this.reason){
					uni.showToast({
						title:"请输入拒单原因！",
					})
					return
				}
				this.$get('recovery/refuseorder', {
					id:this.searchObj.id,
					reason:this.reason,
				}, (res) => {
					uni.showToast({
						title:"您已拒绝当前订单，系统会继续派单！",
					})
				})
			}
		},
		onLoad() {
			this.getOrder()
		},
		onUnload(){
			clearInterval(this.aroundGet)
		}
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
		padding: 0 34rpx;
	}
	.top{
		font-size: 28rpx;
	}
	.get{
		text-align: center;
		margin-top: 70rpx;
	}
	.get image,.no image{
		width: 340rpx;
		height: 340rpx;
	}
	.text{
		text-align: center;
		color: #666666;
		font-size: 32rpx;
	}
	.no{
		text-align: center;
		margin-top: 70rpx;
	}
	.input_box input{
		width: 580rpx;
		height: 88rpx;
		line-height: 88rpx;
		border-radius: 88rpx;
		background: #F3F3F3;
		margin: 0 auto;
		font-size: 32rpx;
	}
	

</style>
